package com.lesama.test;

import java.util.Random;
import java.util.Scanner;

public class RandomNum {
    public static void main(String[] args) {
        RandomNumGame();
    }
    public static void RandomNumGame() {
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        int randomNum = r.nextInt(500) + 1; // 生成一个范围在 1 - 500 的随机数
        while(true) {
            System.out.println("请输入一个1 - 500的数字");
            int num = sc.nextInt();
            if(num > randomNum) {
                System.out.println("您输入的数字太大了");
            } else if(num < randomNum) {
                System.out.println("您输入的数字太小了");
            } else {
                System.out.println("猜对了");
                break;
            }
        }
    }
}
